package com.twu.biblioteca.MenuItems;

import com.twu.biblioteca.Libraries.BooksLibrary;
import com.twu.biblioteca.Session;
import com.twu.biblioteca.UserAccount;

import java.util.Scanner;
import java.util.*;

public class ReserveBookItem extends MenuItem {

    private BooksLibrary booksLibrary = new BooksLibrary();


    public ReserveBookItem(String description) {

        this.description = description;
    }

    @Override
    public boolean controller(UserAccount sessionUser) {

        printBooksList();
        Session session = new Session();

        if( session.login(sessionUser , 2) ) {

            System.out.println("Enter book's ISBN code : ");
            Scanner isbnScanner = new Scanner(System.in);
            String isbn = isbnScanner.next();

            try {
                booksLibrary.reserveBook(isbn);
            }

            catch(ArrayIndexOutOfBoundsException E){
                System.out.println("Invalid Book Id!!");
            }
        }

        return false;
    }

    void printBooksList() {

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        System.out.println("~~~~~~~~~~ Books ~~~~~~~~~~~~");
        Vector<String> booksDetails = new Vector<String>(booksLibrary.getAllItemDetails());
        for (int i = 0; i < booksDetails.size(); i++)
            System.out.println((i + 1) + "." + booksDetails.elementAt(i));
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

    }
}
